package com.thuan.hibernate;

import java.sql.Date;
import java.util.List;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.thuan.db.LeagueDAO;
import com.thuan.db.UserDAO;
import com.thuan.pojo.Competition;
import com.thuan.pojo.League;
import com.thuan.pojo.UserAccount;

public class Repository {
	private static ApplicationContext context = new ClassPathXmlApplicationContext("spring.xml");
	private static UserDAO userBo = (UserDAO)context.getBean("userDAO");
	private static LeagueDAO leagueBo = (LeagueDAO) context.getBean("leagueDAO");
	
	
	public static List<UserAccount> getUsers() {
		return userBo.getUsers();
	}
	
	public static int addUser(String username, String password, String name) {
		return userBo.addUser(username, password, name);
	}
	
	public static UserAccount findUser(String username) {
		return userBo.findUser(username);
	}
	
	public static boolean updateName(String username, String name) {
		return userBo.updateName(username, name);
	}
	
	public static boolean updatePassword(String username, String password) {
		return userBo.updatePassword(username, password);
	}
	
	public static boolean updateSigninTime(String username, Date signinTime) {
		return userBo.updateSigninTime(username, signinTime);
	}
	
	public static List<League> listLeagues() {
		return leagueBo.listLeagues();
	}
	
	public static int addLeague(String name, Date startDate, Date endDate,
			int rewardId) {
		return leagueBo.addLeague(name, startDate, endDate, rewardId);
	}
	
	public static Competition findCompetition(UserAccount playerA, UserAccount playerB) {
		return leagueBo.findCompetition(playerA, playerB);
	}
	
	public static int addCompetition(int leagueId, String usernamePlayerA,
			String usernamePlayerB, String usernameWinner) {
		return leagueBo.addCompetition(leagueId, usernamePlayerA, usernamePlayerB, usernameWinner);
	}
	
	public static List<UserAccount> getWinners(League league) {
		return leagueBo.getWinners(league);
	}
	
	public static League findLeague(String name) {
		return leagueBo.findLeague(name);
	}

	public static boolean login(String username, String password) {
		return userBo.login(username, password);
	}
	
	

}
